package medicalDocumentation.medicalDoc;

import entity.PatientDischarge;

import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateful
public class CaseDischargeSessionBean implements CaseDischargeSessionBeanRemote {

    @PersistenceContext
    private EntityManager em;
    
    @Override
    public Long addNewCaseDischarge(String cin, String name, String pin, String state, String treatment){
        PatientDischarge discharge = new PatientDischarge();
        discharge.setCin(cin);
        discharge.setPatientName(name);
        discharge.setPin(pin);
        discharge.setCurrentPatientState(state);
        discharge.setFurtherTreatment(treatment);
        em.persist(discharge);
        em.flush();
        return discharge.getId();
    }
    
    @Override
    public PatientDischarge getDischarge(Long id){
        PatientDischarge pd = em.find(PatientDischarge.class, id);
        return pd;
    }
    
    @Override
    public void deleteDischarge(Long id) {
        PatientDischarge pd = em.find(PatientDischarge.class, id);
        em.remove(pd);
        em.flush();
    }
}
